<?
include_once("cmsConfig.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Google Maps API Example - Geocoding API</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=<?= GOOGLE_MAPS_KEY; ?>" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    var map = null;
    var geocoder = null;
    var point = null;
    var longitude = null;
    var latitude = null;

    
    function load() {
	    //This function should be called on body onload.
	    //It should check if the parent window form field contains coordinates
	    //If coordinates exist, it should call function to 
    }
    
    function insert() {
	    
    }
    

   function showAddress(address, markerText) {
	   if (GBrowserIsCompatible()) {
		   
		   //Start up maps...
		   map = new GMap2(document.getElementById("map"));
		   geocoder = new GClientGeocoder();
		   
		   //Add zoom controls
		   map.addControl(new GSmallMapControl());
		   
		   //Add type controls
		   map.addControl(new GMapTypeControl());
		   
	   }
	   if (geocoder) {
		   geocoder.getLatLng(
		   address,
		   function(point) {
			   if (!point) {
				   alert(address + " not found");
			   }
			   else {
				   
				   //Set map center to point found from address
				   map.setCenter(point, 16);
				   
				   //Create draggable marker and set point in centre
				   var marker = new GMarker(point, {draggable: true});
				   
				   //Add Listener to close marker when user drags marker
				   GEvent.addListener(marker, "dragstart", function() {
					   map.closeInfoWindow();
				   });
				   
				   //Add Listener to re-open info window in correct location when marker is moved
				   GEvent.addListener(marker, "dragend", function() {
					   marker.openInfoWindowHtml(markerText);
					   point = marker.getPoint();
					   longitude = point.x;
					   latitude = point.y;
				   });

				   //Overlay the marker on the map
				   map.addOverlay(marker);
				   
				   //Open info window on marker with marker text
				   marker.openInfoWindowHtml(markerText);
				   
				   //Turn insert map button on
				   document.getElementById("insert").style.display = "";
				   
				   //for (var pro in marker) {
					   //alert(marker[pro]);
				   //}
			   }
		   }
		   );
	   }
   }
    //]]>
    </script>
  </head>

  <body onload="" onunload="GUnload();">
    <form action="#" onsubmit="showAddress(this.address.value,this.markerText.value); return false">
      <p>
        Address: <input type="text" size="50" name="address" value="" />
	<br />
	Marker Text: <textarea name="markerText" cols="40"></textarea>
	<br />
        <input type="submit" value="Go!" />
      </p>
      <div id="map" style="width: 500px; height: 300px"></div>
      <div id="insert" style="display:none;"><button type="button" onClick="javascript:insertMap();">Insert Map</button></div>
    </form>

  </body>
</html>

